import {
	request
} from '@/request/index.js';

let App = getApp().globalData;

export const distributeOrder = {
	methods: {
		// 获取分销订单
		getDistributionOrder({
			type = '',
			orderState = 3,
			specified = '',
			search = ''
		} = {}) {
			// {type:1我的分销员订单，2:我的客户订单, '' 所有分销订单}
			let obj = {
				specified: specified, //{客户订单传：uid,分销员订单传distributor_id}
				page: this.page,
				limit: this.limit,
				search: search,
				type: type,
				withdraw_state: orderState
			}
			request('Distribution/MiniOrder/getDistriOrder', obj).then(res => {
				if (res.status == 1) {
					if (res.data && res.data.list && res.data.list.length > 0) {
						this.list = this.list.concat(res.data.list);
						this.tip = '我是有底线的';
					} else {
						this.list = []
						this.tip = '暂无数据';
					}
					this.count = res.data.count;
					this.isLoading = false;
					this.isIcon = false;
				} else {
					this.list = [];
					this.isIcon = true;
					this.tip = '暂无数据';
					this.isLoading = false;
					App.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			})
		},
	},
}


export const distributeGoods = {
	methods: {
		// 获取分销商品
		getDistributionGoods(type = 1) {
			// {type,1是部分2列表}
			let obj = {
				page: this.page,
				limit: this.limit,
				search: this.search,
			}
			request('Distribution/MiniDistributor/getDistributionGoods', obj).then(res => {
				if (res.status == 1) {
					if (res.data && res.data.list && res.data.list.length > 0) {
						if (type == 1) {
							this.list = res.data.list
						} else {
							this.count = res.data.count;
							this.isLoading = false;
							this.isIcon = false;
							this.tip = '我是有底线的';
							this.list = this.list.concat(res.data.list);
						}
					}
				} else {
					if (type === 3) {
						this.list = [];
						this.isIcon = true;
						this.tip = '暂无数据';
						this.isLoading = false;
					}
					this.list = [];
				}
			})
		},
	}
}
